package org.dean.webapps.projectname.presentation.commands.convertors;

import org.apache.commons.lang.StringUtils;
import org.dean.webapps.projectname.constants.ApplicationSettingConstant;
import org.dean.webapps.projectname.presentation.commands.user.UserLoginInCmd;
import org.dean.webapps.projectname.presentation.commands.user.UserRegisterInCmd;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 * User: dean
 * Date: 8/23/11
 * Time: 11:45 AM
 * To change this template use File | Settings | File Templates.
 */
public class UserConvertor {

    public static UserLoginInCmd request2LoginInCmd(HttpServletRequest request) {
        UserLoginInCmd cmd = new UserLoginInCmd();
        cmd.setUsername(request.getParameter("login_username"));
        cmd.setPassword(request.getParameter("login_password"));
        String rememberMeChk = request.getParameter("login_remember_me_flg");
        if (!StringUtils.isEmpty(rememberMeChk)) {
            cmd.setRemember(true);
        } else {
            cmd.setRemember(false);
        }

        return cmd;
    }

    public static UserRegisterInCmd request2RegisterInCmd(HttpServletRequest request) {
        UserRegisterInCmd cmd = new UserRegisterInCmd();
        cmd.setUserName(request.getParameter("register_username"));

        cmd.setEmail(request.getParameter("register_email"));
        cmd.setPassword(request.getParameter("register_password"));
        //
        cmd.setPhoneNumber(request.getParameter("register_phone"));
        cmd.setFirstName(request.getParameter("register_first_name"));
        cmd.setLastName(request.getParameter("register_last_name"));
        cmd.setSex(request.getParameter("register_sex"));
        if(StringUtils.isEmpty(cmd.getFirstName())){
            cmd.setFirstName(ApplicationSettingConstant.UNKNOWN_NAME);
        }
        if(StringUtils.isEmpty(cmd.getLastName())){
            cmd.setLastName(ApplicationSettingConstant.UNKNOWN_NAME);
        }
        return cmd;
    }



}
